//
//  LGUploadProgressView.m
//  HeartDisease_YHJK
//
//  Created by 1234 on 2025/1/7.
//

#import "LGUploadProgressView.h"

@interface LGUploadProgressView()

/**   */
@property (nonatomic , strong)UIProgressView *progressView;

@end

@implementation LGUploadProgressView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.progressView = [[UIProgressView alloc]init];
        [self addSubview:self.progressView];
        [self.progressView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(viewPix(20));
            make.right.equalTo(self).offset(-viewPix(20));
            make.centerY.equalTo(self);
            make.height.equalTo(@(20));
        }];
    }
    return self;
}

+ (instancetype)showHUDAddedTo:(UIView *)view tintColor:(NSString *)tintColor  progressColor:(NSString *)progressColor{
    LGUploadProgressView *progressView = [[self alloc] initWithFrame:view.bounds];
    progressView.progressView.trackTintColor = [UIColor colorWithString:tintColor];
    progressView.progressView.progressTintColor = [UIColor colorWithString:progressColor];
    [view addSubview:progressView];
    return progressView;
}

+ (BOOL)hideHUDForView:(UIView *)view animated:(BOOL)animated {
    LGUploadProgressView *hud = [self HUDForView:view];
    if (hud != nil) {
//        hud.removeFromSuperViewOnHide = YES;
//        [hud hideAnimated:animated];
        return YES;
    }
    return NO;
}

+ (LGUploadProgressView *)HUDForView:(UIView *)view {
    NSEnumerator *subviewsEnum = [view.subviews reverseObjectEnumerator];
    for (UIView *subview in subviewsEnum) {
        if ([subview isKindOfClass:self]) {
            LGUploadProgressView *hud = (LGUploadProgressView *)subview;
//            if (hud.hasFinished == NO) {
//                return hud;
//            }
        }
    }
    return nil;
}

@end
